package com.briup.web;

import com.briup.pojo.Customer;
import com.briup.pojo.Shopcar;
import com.briup.service.IShopCarService;
import com.briup.serviceImp.ShopCarServiceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UpdateShopCartServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.parseInt(request.getParameter("id"));
        Integer num = Integer.parseInt(request.getParameter("num"));
        Customer customer = (Customer) request.getSession().getAttribute("login");
        if (customer == null){
            request.getRequestDispatcher("/login.jsp").forward(request,response);
        }
        Shopcar shopcar1 = new Shopcar(customer.getId(), id, num);
        IShopCarService shopCarServiceImp = new ShopCarServiceImp();
        shopCarServiceImp.updateShopCar(shopcar1);
        request.getRequestDispatcher("/shopcar").forward(request,response);
    }
}
